﻿using B.S.Production.ErrorCode;
using MediatR;
using SqlSugar;
using Warehouse.Domain;
using Warehouse.ErrorCord;
using Warehouse.Read.Api.Actions.Command.WarehouseCategory;

namespace Warehouse.Read.Api.Actions.CommandHandel.WarehouseCategory
{
    public class GetShowCommandHandle : IRequestHandler<GetShowCommand, APIResult<List<WarehouseInformation>>>
    {
        private readonly ISqlSugarClient db;

        public GetShowCommandHandle(ISqlSugarClient db)
        {
            this.db = db;
        }

        public async Task<APIResult<List<WarehouseInformation>>> Handle(GetShowCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<WarehouseInformation>> result = new APIResult<List<WarehouseInformation>>();
            var list = await db.Queryable<WarehouseInformation>().ToListAsync();
            result.Data = list;
            if (result.Data != null)
            {
                result.Code = APIEnum.Success;
                result.Msg ="查询成功" ;
            }
            else
            {
                result.Code = APIEnum.Fail;
                result.Msg = "查询失败";
            }
            return result;
            
        }
    }
}
